package com.xiaoshuidi.cloud.module.rooms.enums;

import cn.hutool.core.util.StrUtil;
import com.xiaoshuidi.cloud.module.rooms.vo.RoomDevicePeakValleyPriceVo;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * @Author Feng
 * @date 2023/4/27
 */
@Getter
@AllArgsConstructor
public enum DevicePriceType {
    DEVICE_PRICE_STEP(1,"阶梯"),
    DEVICE_PRICE_UNSTEP(2,"非阶梯"),
    DEVICE_PRICE_NORMAL(3,"常规"),
    DEVICE_PRICE_PEAKVALLEY(4,"峰谷");

    private int code;
    private String name;


    public static String getNameByCode(String code) {
        if (StrUtil.isEmpty(code)) {
            return null;
        }
        Optional<DevicePriceType> find = Arrays.stream(DevicePriceType.values()).filter(s -> ((s.getCode()+"").equals(code))).findFirst();
        if (find.isPresent()) {
            return find.get().getName();
        }
        return null;
    }

    /**
     * 配置页面选中的 峰谷电还是常规电
     * @param ammterType
     * @return
     */
    public static int getCodeByAmmterType(Integer ammterType) {
        if (RoomDevicePeakValleyPriceVo.AMMTER_TYPE_NORMAL.equals(ammterType)) {
            return DEVICE_PRICE_NORMAL.getCode();
        }
        if (RoomDevicePeakValleyPriceVo.AMMTER_TYPE_PEAK_VALLEY.equals(ammterType)) {
            return DEVICE_PRICE_PEAKVALLEY.getCode();
        }
        return DEVICE_PRICE_STEP.getCode();
    }

    /**
     * 当前枚举类型 对应配置页面中的峰谷还是常规
     * @param code 当前枚举类型
     * @return
     */
    public static Integer getAmmterTypeByCode(Integer code) {
        if (DEVICE_PRICE_NORMAL.getCode() == code) {
            return RoomDevicePeakValleyPriceVo.AMMTER_TYPE_NORMAL;
        }
        if (DEVICE_PRICE_PEAKVALLEY.getCode() == code) {
            return RoomDevicePeakValleyPriceVo.AMMTER_TYPE_PEAK_VALLEY;
        }
        return null;
    }
}
